<template>
    <div class="app-container">
        <div style="text-align:right;padding-bottom: 10px">
            <!-- <el-button type="primary" @click="$router.push('/operate/article/add')">添加</el-button> -->
        </div>
        <el-table :key="tableKey" v-loading="listLoading" :data="log_list" border fit highlight-current-row style="width: 100%" @sort-change="sortChange">
            <el-table-column :label="$t('table.id')" prop="id" align="center" width="80">
                <template slot-scope="{ row }">
                    <span>{{ row.id }}</span>
                </template>
            </el-table-column>
            <el-table-column :label="$t('日志')" prop="operation" align="center">
                <template slot-scope="{ row }">
                    <span>{{ row.operation }}</span>
                </template>
            </el-table-column>
            <el-table-column :label="$t('时间')" prop="createtime" align="center" width="180">
                <template slot-scope="{ row }">
                    <span>{{ row.createtime }}</span>
                </template>
            </el-table-column>
            <!-- <el-table-column :label="$t('table.actions')" align="center" width="230" class-name="small-padding fixed-width">
                <template slot-scope="{ row, $index }">
                    <input :id="'wxapp_url_'+row.id" :value="'/article/pages/article/index?id=' + row.id" style="position: relative;z-index: -1" />
                    <el-button size="mini" type="primary" @click="handleCopy(row, $index)">
                        {{ $t("复制链接") }}
                    </el-button>
                    <el-button size="mini" type="primary" @click="handleUpdate(row, $index)">
                        {{ $t("编辑") }}
                    </el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(row, $index)">
                        {{ $t("table.delete") }}
                    </el-button>
                </template>
            </el-table-column> -->
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
</template>

<script>
import { list } from '@/platform/api/log/log'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
    components: { Pagination },
    data() {
        return {
            log_list: [],
            total: 0,
            tableKey: 0,
            listLoading: true,
            listQuery: {
                page: 1,
                limit: 20,
                importance: undefined,
                title: undefined,
                type: undefined,
                sort: '+id'
            }
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            this.listLoading = true
            list(Object.assign({}, this.listQuery)).then(res => {
                this.log_list = res.data.items
                this.total = res.data.total
                this.listLoading = false
            })
        },
        getSortClass(key) {
            const sort = this.listQuery.sort
            return sort === `+${key}` ? 'ascending' : 'descending'
        },
        sortChange(data) {
            const { prop, order } = data
            if (prop === 'id') {
                this.sortByID(order)
            }
        },
        handleDelete(row, index) {
            deleteArticle({ id: this.log_list[index].id }).then(() => {
                // this.list.unshift(this.temp);
                // this.dialogFormVisible = false;
                this.$notify({
                    title: '成功',
                    message: '删除成功',
                    type: 'success',
                    duration: 2000
                })
                this.log_list.splice(index, 1)
            })
        }
    }
}
</script>

<style>
.img-thumb {
    width: 30px;
    height: 30px;
}
</style>
